#include "tim_app.h"

void Tim_set_duty(uint16_t duty)
{
    TIM2->CCR2 = (TIM2->ARR +1 )* (duty / 100.0f);
}

void Tim_set_freq(uint16_t freq)
{
    uint32_t Clock_freq = 1000000;

    uint32_t value = Clock_freq / freq - 1;

    TIM2->CCR2 = (value + 1) * (TIM2->CCR2 / TIM2->ARR);

    TIM2->ARR = value;

    TIM2->EGR = TIM_EGR_UG;
}

void tim_proc(void)
{
    if(data1.GEAR == 1)
    {
        Tim_set_duty(10);
    }
    else if(data1.GEAR == 2)
    {
        Tim_set_duty(40);
    }
    else if(data1.GEAR == 3)
    {
        Tim_set_duty(80);
    }

}
